package io.jee.runshan.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class StringUtils {
	
	public static boolean blank(String value) {
		return value == null || value.length() == 0;
	}
	
	public static boolean notBlank(String value) {
		return !blank(value);
	}

	public static boolean hasBlank(String... values) {
		if (values == null) {
			return true;
		}
		for (String value : values) {
			if (value == null || value.length() == 0) {
				return true;
			}
		}
		return false;
	}

	public static boolean allBlank(String... values) {
		if (values == null) {
			return true;
		}
		for (String value : values) {
			if (value != null && value.length() > 0) {
				return false;
			}
		}
		return true;
	}
	
	public static String getCurrentTime() {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
		return format.format(new Date());
	}
	
	public static String getRand(int digit) {
		String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < digit; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString().toUpperCase();
	}
}
